<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>DEMO</title>
</head>
<body>
	<script>
		var url = "http://www.jnshu.com:8080/index.html?user=chenapo&age=99#home";
		var reg = /(https?:)\/\/([^\/]+)(\/[^\?]*)?(\?[^#]*)?(#.*)?/;
		var arr = url.match(reg);
		console.log(arr);

		/*var protocol = arr[1];
		console.log(protocol);
		var host = arr[2];
		console.log(host);
		var pathname = arr[3];
		console.log(pathname);
		var search = arr[4];
		console.log(search);
		var hash = arr[5];
		console.log(hash);*/
	</script>
</body>
</html>